package com.loongxun.xxapp.ui.login;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.View;
import android.widget.TextView;

import com.loongxun.xxapp.R;

import org.json.JSONException;

/**
 * 注册界面
 * Created by Administrator on 2017/10/20.
 */
public class RegisterActivity extends Activity implements View.OnClickListener{

    private TextView tv_register_code;
    private TimeCount time;

    private SharedPreferences shared;
    private SharedPreferences.Editor editor;

    private TextView tv_seccess_hint;

    private TextView tv_title;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);

        findViewById(R.id.iv_back).setOnClickListener(this);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_title.setText("注册");

        shared = getSharedPreferences("userInfo", 0);
        editor = shared.edit();//获取编辑器

        tv_register_code = (TextView) findViewById(R.id.tv_register_code);
        tv_register_code.setOnClickListener(this);
        findViewById(R.id.tv_register).setOnClickListener(this);

        time = new TimeCount(60000, 1000);

        tv_seccess_hint = (TextView) findViewById(R.id.tv_seccess_hint);
        tv_seccess_hint.setText("恭喜您注册成功");
        findViewById(R.id.tv_goto_login).setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.iv_back:
                finish();
                break;
            //获取手机验证码
            case R.id.tv_register_code:
                time.start();// 开始计时
                break;
            case R.id.tv_register:
                findViewById(R.id.ll_results_ok).setVisibility(View.VISIBLE);
                break;
            case R.id.tv_goto_login:
//                editor.putString("user_id", "1");
//                editor.commit();//提交修改
//                Intent intent = new Intent();
//                intent.putExtra("login", true);
//                setResult(Activity.RESULT_OK, intent);
                finish();
                break;
            default:
                break;
        }
    }

    class TimeCount extends CountDownTimer {

        public TimeCount(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {// 计时过程
            tv_register_code.setClickable(false);//防止重复点击
            tv_register_code.setText(millisUntilFinished / 1000 + "秒后重新获取");
        }

        @Override
        public void onFinish() {// 计时完毕
            tv_register_code.setText("点击获取验证码");
            tv_register_code.setClickable(true);
        }
    }
}
